<!DOCTYPE >
<html lang="zh-cn">
  <head>
      <title>后台管理-发系统消息</title>
      <% include ./partials/head %>
      <script type="text/javascript">
        var oSend ={
            operator:function(){
                $(".upload").on("click",function(){
                    $parent=$(this).parent();
                    var imgPath = $parent.find(".send_img").val();  
                    if (imgPath == "") {  
                        alert("请选择上传图片！");  
                        return;  
                    } 
                    var data = new FormData();
                    data.append('img',$parent.find(".send_img")[0].files[0]);
                    $.ajax({
                        url:"/admin/article/upload",
                        type:"POST",
                        data:data,
                        cache:false,
                        contentType:false,
                        processData:false,
                        success:function(json){
                            if(json.code==0){
                                $parent.find(".imgurl").html(json.url);
                                $parent.find(".img")[0].src=json.url;
                            }else{
                                alert(json.msg);
                            }
                        }
                    })

                })
                $("#certain_send").on('click',function(){
                    $this = $(this)
                    if(window.confirm('你确定发送吗？')){
                        // 0全部，1编辑推荐
                        $.post("/send",{
                            "sendType":$this.attr("type"),
                            "content":$("#send_content").val(),
                            "title":$("#send_title").val(),
                            "imgurl":$(".imgurl").html()
                        },function(json){
                            if(json.code==0){
                                history.go(0) 
                            }else{

                            alert(json.msg);
                            }
                        },'json');
                    }else{
                        //取消
                    }
                })
            },
            change:function(){
                var type =window.location.href.split("=")[1];
                if(type ==1){
                    $("#certain_send").attr("type",1);
                }else{
                    $("#certain_send").attr("type",0);
                }
                $("#send-filter").on("change",function(){
                    var value = $(this).children('option:selected').val(); 
                    window.location.href="/admin/sysMsg?sendType="+value;
                })
            },
            init:function(){
                this.operator();
                this.change();
            }
        }
        $(document).ready(function(){
            oSend.init();
        })
      </script>
  </head>
  <body>
    <header>
      <% include ./partials/header %>
    </header>
    <div class="ch-container">
      <% include ./partials/sidebar %>
              <!-- 页面内容 -->
        <div id="content" class="col-lg-10 col-sm-10">
          <div class="row">
            <div class="box col-md-12">
              <div class="box-inner">
                <div class="box-header well" data-original-title="">
                  <h2><i class="glyphicon glyphicon-edit"></i> 群发消息 </h2>
                </div>
                <div class="box-header well" data-original-title="">
                <div class="control-group">
                  <div class="controls">
                    <label class="control-label" for="selectError">筛选:&nbsp&nbsp&nbsp </label>
                    <select id="send-filter" data-rel="chosen">
                        <option>选择</option>
                        <option value="0">全部人</option>
                        <option value="1" >编辑推荐</option>
                    </select>
                  </div>
                  
                </div>
              </div>
                <div class="box-content">

                  <div class="form-group">
                    <label for="exampleInputEmail1">发送给:&nbsp&nbsp&nbsp 
                        <% if (sendType==0) { %>
                            全部人
                        <% }else{ %>
                            编辑推荐
                        <% } %>
                    </label>
                  </div>
                    <div class="form-group">
                        <label for="exampleInputEmail1">回复</label>                       
                        <textarea id="send_content" rows="5" class="form-control"></textarea>
                    </div>
                    <p>若为图文消息请添加以下内容:(不填写为普通的文字消息)</p>
                    <div class="form-group">
                        <label for="exampleInputEmail1">标题：</label>                       
                        <input id="send_title" rows="5" class="form-control"></textarea>
                    </div>
                    <div class="form-group">
                        <label>标题图片:</label>
                        <input type="file" class="send_img" name="Img">
                        <span class="btn btn-default upload"  >
                            <i class="glyphicon glyphicon-plus green"></i>上传
                        </span>
                        <img class="grayscale img" style="max-height:100px">
                        <span class="imgurl"></span>
                    </div>
                    <button id="certain_send" class="btn btn-success"><i class="glyphicon glyphicon-shopping-cart"></i>
                        确定</button>

                </div>


              </div>
            </div>
          </div>
        </div>

      <% include ./partials/footer %>
    </div>
    <% include ./partials/external %>

  </body>
</html>
